import * as types from './mutation-types.js'

const mutations = {
  [types.LOGIN]: (state, data) => {
    localStorage.token = data;
    state.token = data;
  },
  [types.LOGOUT]: (state) => {
    localStorage.removeItem('token');
    localStorage.removeItem('user');
    state.token = null
  },
  [types.RELOGIN]: (state, data) => {
    localStorage.token = data;
    state.token = data;
  },
  [types.USER]: (state, data) => {
    localStorage.user = JSON.stringify(data);
    state.user = data;
  },
  [types.REUSER]: (state, data) => {
    localStorage.user = data;
    state.user = JSON.parse(data);
  }
}

export default mutations
